<div class="content-auto">
<div class="breadcrumb">
<?php
if($cat == 3)
    echo '<span>(<strong>Inventory</strong>=== FA)</span>';
else
    echo '<span>(<strong>Inventory</strong>=== NA)</span>';
?>
</div>
<?php echo form_open('inventory/assetedit',array('class'=>'form-horizontal form-validate','id'=>'frm'));?>
<fieldset>
    <legend><h4><?php echo $title;?></h4></legend>
    <table class="table-form-submit">
        <tr>
    <?php
       if($cat == 3){
           echo '<td><label for="item">FA Type</label></td>';
           echo '<td>'.form_dropdown('fatype_id', $faList, $stock['fatype_id'], 'class="form-control fa-select"').'</td>';
       }
       elseif($cat == 4)
       {
           echo '<td><label for="item">NA Type</label></td>';
           echo '<td>'.form_dropdown('natype_id', $naList, $stock['natype_id'], 'class="form-control na-select"').'</td>';
       }
    ?>
        </tr>
        <tr>
            <td><label for="item">Item *</label></td>
            <td><input type="text" name="item" value="<?php echo $stock['item']; ?>" placeholder="item name" class="form-control" required /></td>
        </tr>
        <tr>
            <td><label for="code">Code</label></td>
            <td><input type="text" name="code" value="<?php echo $stock['code']; ?>" placeholder="code item" class="form-control control-width" /></td>
        </tr>
         <tr>
            <td><label for="unit">Unit *</label></td>
             <td>
            <?php
                $inunit = id_clean($stock['bought']) - (id_clean($stock['unitused']) + id_clean($stock['unitbroken']));  
            ?>
                <span>(Bought: <?php echo $stock['bought'].', ';?></span>
                <span>In stock: <?php echo $inunit;?>)</span>
            <?php if(isset($stock['assign_id']) && $stock['assign_id'] != null && $stock['assign_id'] != '') { ?>
                <input type="text" name="unit" value="<?php echo $stock['bought']; ?>" readonly="readonly" placeholder="number of items" class="form-control control-width" required />
            <?php }else{ ?>
                <input type="text" name="unit" value="<?php echo $stock['bought']; ?>" placeholder="number of items" class="form-control control-width" required />  
            <?php } ?>   
            </td>
        </tr>
        <tr>
            <td><label for="cpu">Cost Per Unit *</td>
            <td>
            <?php if(isset($stock['assign_id']) && $stock['assign_id'] != null && $stock['assign_id'] != '') { ?>
                <input type="text" name="cpu" value="<?php echo $stock['cpu']; ?>" readonly="readonly" placeholder="cost per unit" class="form-control control-width" required />
            <?php }else{ ?>
                <input type="text" name="cpu" value="<?php echo $stock['cpu']; ?>" placeholder="cost per unit" class="form-control control-width" required />  
            <?php } ?>   
            </td>
        </tr>
        <tr>
            <td><label for="datepurchased">Purchased Date *</td>
            <td><input type="text" name="datepurchased" value="<?php echo $stock['datepurchased']; ?>" placeholder="purchased date" data-date-format="yyyy/mm/dd" class="form-control datepicker" required /></td>
        </tr>
        <?php if($inunit > 0){ ?>
        <tr>
            <td><label for="status_id">Status</label></td>
            <td>
                <?php echo form_dropdown('status_id', $statusList,array(), 'class="form-control status-select"') ?>
            </td>
        </tr>
        <?php }else{ $data = array(1=>'In Stock'); ?>
            <tr>
                <td><label for="status_id">Status</label></td>
                <td>
                    <?php echo form_dropdown('status_id', $data,array(), 'class="form-control status-select"') ?>
                </td>
            </tr>
        <?php }?>
        <tr class="hidden-branch-tr">
            <td><label class="branch-hidden"  for="note">Note</td>
            <td><textarea name="note" class="form-control branch-hidden note"></textarea></td>
        </tr>
        <tr class="hidden-broken-tr">
            <td><label class="broken-hidden"  for="notebroken">Note</td>
            <td><textarea name="notebroken" class="form-control broken-hidden note"></textarea></td>
        </tr>
        <tr class="hidden-branch-tr">
            <td><label  class="branch-hidden" for="dateused">Date </td>
            <td><input type="text" name="dateused" value="<?php echo isset($stock['dateused']) ? $stock['dateused']:''; ?>" placeholder="used or transfered date" data-date-format="yyyy/mm/dd" class="form-control branch-hidden datepicker" /></td>
        </tr>
        <tr class="hidden-branch-tr">
            <td><label class="branch-hidden" for="unitused">Unit *</label></td>
            <td><input type="text" name="unitused" value="<?php echo $stock['unitused']; ?>" placeholder="number of items" class="form-control control-width branch-hidden" required /></td>
        </tr>
    <?php if(isset($_SESSION['branch']) && $_SESSION['branch'] == '00HO00') { ?>
        <tr class="hidden-branch-tr">
            <td><label  class="branch-hidden" for="branch_id">Office *</label></td>
            <td>
                <?php echo form_dropdown('branch_id', $branchList, array(), 'class="form-control branch-hidden" id="branch_id" required') ?>
            </td>
        </tr>
         <tr class="hidden-branch-tr location-tr">
            <td><label  class="branch-hidden" for="location_id">Location</label></td>
            <td>
                <?php echo form_dropdown('location_id', $locationList, array(), 'class="form-control branch-hidden" id="location_id"') ?>
            </td>
        </tr>
    <?php } else {
        echo form_hidden('branch_id', $_SESSION['branch']);
    }?>
        <tr class="hidden-branch-tr">
            <td><label class="branch-hidden" for="staff">Staff</label></td>
            <td><input type="text" name="staff" value="<?php echo isset($stock['staff']) ? $stock['staff']:''; ?>" placeholder="Staff name" class="form-control control-width branch-hidden" /></td>
        </tr>
        <tr class="hidden-broken-tr type-tr">
            <td><label class="broken-hidden" for="unitbroken">Unit</label></td>
            <td><input type="text" name="unitbroken" value="<?php echo $stock['unitbroken']; ?>" placeholder="Number of items" class="form-control control-width broken-hidden" /></td>     
        </tr>
        <tr>
            <td><label for="remark">Remark</td>
            <td><textarea name="remark" class="form-control"><?php echo $stock['remark']; ?></textarea></td>
        </tr>
        <tr>
            <td></td>
            <td>
                <label class="checkbox">
                <?php if($stock['activate'] == 1){ ?>
                    <input name="activate" type="checkbox" checked="checked" /> Active
                <?php }else { ?>
                    <input name="activate" type="checkbox" /> Active
                <?php } ?>
                </label>
            </td>
        </tr>
        <tr>
            <td></td>
            <td>
                <?php 
                    echo form_hidden('category_id',$cat);
                    echo form_hidden('stock_id',$stock['stock_id']);
                    echo form_hidden('item_id',$stock['item_id']);
                ?>
                <?php echo $form; ?>
            </td>
        </tr>
    </table>
 </fieldset> 
<?php echo form_close();?>
</div>